//
//  CollectTableViewCell.m
//  MMLOOK
//
//  Created by dllo on 15/10/6.
//  Copyright © 2015年 武俊娥. All rights reserved.
//

#import "CollectTableViewCell.h"
#import "WedModel.h"
#import "UIImageView+WebCache.h"

@interface CollectTableViewCell ()


@property(nonatomic, retain)UIImageView *image;
@property(nonatomic, retain)UILabel *nameLabel;
@property(nonatomic, retain)UILabel *priceLabel;
@property(nonatomic, retain)UILabel *likeLabel;

@end

@implementation CollectTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        
        self.image = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 130, 130)];
        self.image.clipsToBounds = YES;
        self.image.layer.cornerRadius = 10;
        [self.contentView addSubview:self.image];
        [_image release];
        
        self.nameLabel = [[UILabel alloc]init];
        self.nameLabel.numberOfLines = 0;
        self.nameLabel.textColor = [UIColor lightGrayColor];
        [self.contentView addSubview:self.nameLabel];
        [_nameLabel release];
        
        
        self.priceLabel = [[UILabel alloc]initWithFrame:CGRectMake(150, 140 - 55, ([UIScreen mainScreen].bounds.size.width - 160 )/ 2, 50)];
        self.priceLabel.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:self.priceLabel];
        [_priceLabel release];
        
        
        self.likeLabel = [[UILabel alloc]initWithFrame:CGRectMake(150 + ([UIScreen mainScreen].bounds.size.width - 160 )/ 2, 140 - 55, ([UIScreen mainScreen].bounds.size.width - 160 )/ 2, 50)];
        
        self.likeLabel.textAlignment = NSTextAlignmentLeft;
        [self.contentView addSubview:self.likeLabel];
        [_likeLabel release];
        
        
    }
    
    return self;
}


-(void)layoutSubviews
{
    [super layoutSubviews];
    
    
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:17]};
    
    CGRect rect =  [self.nameLabel.text boundingRectWithSize:CGSizeMake(self.frame.size.width - 160, 10000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    
    self.nameLabel.frame = CGRectMake(150, 25, self.frame.size.width - 160, rect.size.height);
    
    
}

-(void)setModel:(WedModel *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    
    
    [self.image sd_setImageWithURL:[NSURL URLWithString:model.photo_path] placeholderImage:[UIImage imageNamed:@""]];
    
    self.nameLabel.text = model.introduce;
    
    self.priceLabel.text = [NSString stringWithFormat:@"￥%@",[model.price stringValue]];
    
    self.likeLabel.text = [NSString stringWithFormat:@"⭐️%@",[model.like_count stringValue]];
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
